home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-10-19 | 3.2 KB | 102 lines | [TEXT/KAHL] |
- // Error.c
- //
- // A simply little error window to display a message sent by the
- // programmer. I use it to tell me what I was doing before I bombed!
- //
- // This file needs "errorIcon.r" to work
- // use this to report an error to the user. Better used for debugging, but it
- // could be modified any way you see fit. Uses the icon provided in "errorIcon.r"
-
- // Prototypes
- void ReportError( Str255 errorMsg );
- Boolean CompareStr( Str255 srcA, Str255 srcB );
-
- // globals
- extern Main myMain;
-
- /******************************************************************************
-
- A simple procedure for reporting errors.
-
- *******************************************************************************/
- void ReportError( Str255 errorMsg )
- {
- short maxStrSize, iconID, winHorz, winVert, strWidth;
- Rect theRect;
- GrafPtr thePort;
- Point localPt;
-
-
- // store the current port and set up some intial variables
- GetPort( &thePort );
-
- // make sure the error string isn't to large.
- if( errorMsg[0] > 128 ) {
- errorMsg[0] = 128;
- }
-
- // grab our icon dude.
- myMain.icon = GetCIcon( 32000 );
- HLock( (Handle)myMain.icon );
-
- // position the window in global coordinates to center on the main screen.
- SetRect( &theRect, 0, 0, 400, 200 );
- myMain.error = NewCWindow( nil, &theRect, "\p", FALSE, dBoxProc,
- (WindowPtr)-1, false, ERROR_WINDOW );
- SetPort( myMain.error );
-
- // set the text stuff up
- TextFont( 9 );
- TextSize( 9 );
- TextFace( 0 );
- strWidth = StringWidth( errorMsg );
-
- // add the size of our icon and the space between it and our text and space along the
- // window frame. we will use this to size our window.
- strWidth += 32 + 14 + 28;
-
- // make sure that it's not to small. just in case.
- if( strWidth < 100 ) {
- strWidth = 100;
- }
-
- // no let's resize our window to fit the size.
- winHorz = ( qd.screenBits.bounds.right - qd.screenBits.bounds.left ) / 2;
- winVert = ( qd.screenBits.bounds.bottom - qd.screenBits.bounds.top ) / 3;
- SizeWindow( myMain.error, strWidth, 60, TRUE );
- MoveWindow( myMain.error, winHorz - (strWidth / 2), winVert, TRUE );
- ShowWindow( myMain.error );
-
- // draw our nifty icon dude.
- SetRect( &theRect, (*myMain.error).portRect.left + 14, (*myMain.error).portRect.top + 14,
- (*myMain.error).portRect.left + 46, (*myMain.error).portRect.top + 46 );
- PlotCIcon( &theRect, myMain.icon );
-
- // draw the error message.
- MoveTo( 60, 25 );
- TextFace( 1 );
- DrawString( "\pError Report:" );
- TextFace( 0 );
- MoveTo( 60, 40 );
- DrawString( errorMsg );
-
- // store the message for later retrieval
- BlockMove( &errorMsg[0], &myMain.errMsg[0], errorMsg[0] );
-
- // do a system beep just for the excitement of things.
- SysBeep( 1 );
-
- // just create a little loop untill the user presses the mouse button
- do {
- } while ( !Button());
-
- // Handle anything we might of done.
- HUnlock( (Handle)myMain.icon );
- DisposCIcon( myMain.icon );
- DisposeWindow( myMain.error );
-
- // Exit the application. This could be avoided if perhaps you test for a fatal error
- // then just past TRUE or FALSE to exit. But I'm to lazy, it either works or it doesn't
- // Also you may wish to clean some things up before you do this.
- ExitToShell();
- }